package com.mce.nebula.entity;

import com.mce.nebula.common.BaseEntity;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 租户服务信息实体，对应Python的TenantServiceInfo模型
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "tenant_service", 
       uniqueConstraints = @UniqueConstraint(columnNames = {"tenant_id", "service_alias"}))
public class TenantService extends BaseEntity {
    
    @Column(name = "service_id", length = 32, unique = true, nullable = false)
    private String serviceId;
    
    @Column(name = "tenant_id", length = 32, nullable = false)
    private String tenantId;
    
    @Column(name = "service_key", length = 32, nullable = false)
    private String serviceKey;
    
    @Column(name = "service_alias", length = 100, nullable = false)
    private String serviceAlias;
    
    @Column(name = "service_cname", length = 100)
    private String serviceCname;
    
    @Column(name = "service_region", length = 64, nullable = false)
    private String serviceRegion;
    
    @Column(name = "description", length = 200)
    private String description;
    
    @Column(name = "category", length = 15, nullable = false)
    private String category; // application,cache,store
    
    @Column(name = "service_port", nullable = false)
    private Integer servicePort = 0;
    
    @Column(name = "is_web_service", nullable = false)
    private Boolean isWebService = false;
    
    @Column(name = "version", length = 255, nullable = false)
    private String version;
    
    @Column(name = "update_version", nullable = false)
    private Integer updateVersion = 1;
    
    @Column(name = "image", length = 200, nullable = false)
    private String image;
    
    @Column(name = "cmd", length = 2048)
    private String cmd;
    
    @Column(name = "min_node", nullable = false)
    private Integer minNode = 1;
    
    @Column(name = "min_cpu", nullable = false)
    private Integer minCpu = 500;
    
    @Column(name = "container_gpu", nullable = false)
    private Integer containerGpu = 0;
    
    @Column(name = "min_memory", nullable = false)
    private Integer minMemory = 256;
    
    @Column(name = "extend_method", length = 32)
    private String extendMethod = "stateless_multiple";
    
    @Column(name = "code_from", length = 20)
    private String codeFrom;
    
    @Column(name = "git_url", length = 2047)
    private String gitUrl;
    
    @Column(name = "git_project_id", nullable = false)
    private Integer gitProjectId = 0;
    
    @Column(name = "service_type", length = 50)
    private String serviceType;
    
    @Column(name = "creater", nullable = false)
    private Integer creater = 0;
    
    @Column(name = "language", length = 40)
    private String language;
    
    @Column(name = "service_origin", length = 15)
    private String serviceOrigin = "assistant";
    
    @Column(name = "tenant_service_group_id", nullable = false)
    private Integer tenantServiceGroupId = 0;
    
    @Column(name = "open_webhooks", nullable = false)
    private Boolean openWebhooks = false;
    
    @Column(name = "service_source", length = 15)
    private String serviceSource;
    
    @Column(name = "create_status", length = 15)
    private String createStatus;
    
    @Column(name = "check_uuid", length = 36)
    private String checkUuid;
    
    @Column(name = "check_event_id", length = 32)
    private String checkEventId;
    
    @Column(name = "docker_cmd", length = 1024)
    private String dockerCmd;
    
    @Column(name = "secret", length = 64)
    private String secret;
    
    @Column(name = "server_type", length = 5)
    private String serverType = "git";
    
    @Column(name = "is_upgrate", nullable = false)
    private Boolean isUpgrate = false;
    
    @Column(name = "build_upgrade", nullable = false)
    private Boolean buildUpgrade = true;
    
    @Column(name = "service_name", length = 100)
    private String serviceName;
    
    @Column(name = "oauth_service_id")
    private Integer oauthServiceId;
    
    @Column(name = "git_full_name", length = 64)
    private String gitFullName;
    
    @Column(name = "k8s_component_name", length = 100)
    private String k8sComponentName;
    
    @Column(name = "job_strategy", length = 2047)
    private String jobStrategy;
    
    @Column(name = "arch", length = 32)
    private String arch = "amd64";
    
    @Override
    public String toString() {
        return this.serviceAlias;
    }
    
    /**
     * 获取组件ID
     */
    public String getComponentId() {
        return this.serviceId;
    }
    
    /**
     * 是否为第三方组件
     */
    public boolean isThirdParty() {
        return "third_party".equals(this.serviceSource);
    }
}





